package com.hhit.collaborative_learning.questions;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hhit.collaborative_learning.utils.DBAccess;

public class ValidatePointServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userId=request.getParameter("userId");
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		int point=0;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("select userPoint from user where userId="+userId);
			rs=ps.executeQuery();
			if(rs.next()){
				point=rs.getInt(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, rs);
		}
		response.getWriter().print(point+"");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

}
